﻿#include "FITKAbsGeoPart.h" 

// Global data
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"

namespace Interface
{
    // 获取数据类型。
    FITKGeoEnum::FITKGeometryComType FITKAbsGeoPart::getGeometryCommandType()
    {
        return FITKGeoEnum::FITKGeometryComType::FGTPart;
    }

    bool FITKAbsGeoPart::backtrackingShape()
    {
        return false;
    }

    void FITKAbsGeoPart::setAutoMergeSolid(bool flag)
    {
        m_autoMergeSolid = flag;
    }

    bool FITKAbsGeoPart::getAutoMergeSolid()
    {
        return m_autoMergeSolid;
    }

    bool FITKAbsGeoPart::update()
    {
        return true;
    }

    void FITKAbsGeoPart::removeDataObj(Core::FITKAbstractDataObject* obj)
    {
        QMutexLocker locker(&_mutex);
        FITKAbsGeoCommand* subCmd = dynamic_cast<FITKAbsGeoCommand*>(obj);
        if (!subCmd)
        {
            return;
        }

        subCmd->removeFromPart(this);
        _helper->removeDataObj(subCmd);
    }

    void FITKAbsGeoPart::removeDataObjWithoutRelease(Core::FITKAbstractDataObject* obj)
    {
        QMutexLocker locker(&_mutex);
        FITKAbsGeoCommand* subCmd = dynamic_cast<FITKAbsGeoCommand*>(obj);
        if (!subCmd)
        {
            return;
        }

        subCmd->removeFromPart(this);
        _helper->removeDataObjWithoutRelease(obj);
    }

    void FITKAbsGeoPart::removeDataByIndex(int index)
    {
        QMutexLocker locker(&_mutex);
        FITKAbsGeoCommand* subCmd = dynamic_cast<FITKAbsGeoCommand*>(_helper->getDataByIndex(index));
        if (!subCmd)
        {
            return;
        }

        subCmd->removeFromPart(this);
        _helper->removeDataObj(subCmd);
    }

    void FITKAbsGeoPart::removeDataByID(int id)
    {
        QMutexLocker locker(&_mutex);
        FITKAbsGeoCommand* subCmd = dynamic_cast<FITKAbsGeoCommand*>(_helper->getDataByID(id));
        if (!subCmd)
        {
            return;
        }

        subCmd->removeFromPart(this);
        _helper->removeDataObj(subCmd);
    }

    void FITKAbsGeoPart::removeDataByName(const QString & name, bool compSens)
    {
        QMutexLocker locker(&_mutex);
        FITKAbsGeoCommand* subCmd = dynamic_cast<FITKAbsGeoCommand*>(_helper->getDataByName(name, compSens));
        if (!subCmd)
        {
            return;
        }

        subCmd->removeFromPart(this);
        _helper->removeDataObj(subCmd);
    }
}